﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.SkinTool
{
    public partial class DisableColorForm : Form
    {
        public DisableColorForm()
        {
            InitializeComponent();
        }

        private void DisableColorForm_Load(object sender, EventArgs e)
        {
            this.trackBar2.Value = this.BackColor.R;
            this.trackBar3.Value = this.BackColor.G;
            this.trackBar4.Value = this.BackColor.B;

            foreach (Control c in this.panel3.Controls)
            {
                Control co = null;
                foreach (Control cds in this.panel1.Controls)
                {
                    if (cds.Text == c.Text)
                    {
                        co = cds;
                        break;
                    }
                }

                c.Text = c.Text + "  " + co.BackColor.GetBrightness().ToString() + "  " + co.BackColor.ToString();
            }
        }

        private void trackBar2_Scroll(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(trackBar2.Value, this.BackColor.G, this.BackColor.B);
            dd();
        }

        private void trackBar3_Scroll(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(this.BackColor.R, trackBar3.Value, this.BackColor.B);
            dd();
        }

        private void trackBar4_Scroll(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(this.BackColor.R, this.BackColor.G, trackBar4.Value);
            dd();
        }

        private void dd()
        {
            foreach (Control c in this.panel2.Controls)
            {
                Control co = null;
                foreach (Control cds in this.panel1.Controls)
                {
                    if (cds.Text == c.Text)
                    {
                        co = cds;
                        break;
                    }
                }


                int color_gray = (this.BackColor.R + this.BackColor.G + this.BackColor.B) / 3;
                Color lightcolor = ControlPaint.LightLight(co.BackColor);
                int lightcolor_gray = (lightcolor.R + lightcolor.G + lightcolor.B) / 3;


                int min = Math.Min(Math.Abs(lightcolor.R - lightcolor_gray), Math.Min(Math.Abs(lightcolor.G - lightcolor_gray), Math.Abs(lightcolor.B - lightcolor_gray)));
                c.BackColor = Color.FromArgb(lightcolor.A, (lightcolor.R > lightcolor_gray ? lightcolor.R - min : lightcolor.R + min), (lightcolor.G > lightcolor_gray ? lightcolor.G - min : lightcolor.G + min), (lightcolor.B > lightcolor_gray ? lightcolor.B - min : lightcolor.B + min));



                color_gray = (c.BackColor.R + c.BackColor.G + c.BackColor.B) / 3;
                color_gray = Math.Min(80, color_gray - 60);
                c.ForeColor = Color.FromArgb(color_gray, color_gray, color_gray);
                // c.BackColor = ControlPaint.Dark(co.BackColor);
            }


        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            button1.BackColor = Color.FromArgb(trackBar1.Value, trackBar1.Value, trackBar1.Value);
            button1.Text = trackBar1.Value.ToString();
        }
    }
}
